package com.compass.doctor.ui.home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.compass.doctor.databinding.LayoutCaseHisPicItemBinding
import com.compass.doctor.databinding.LayoutPatientPictureBinding
import com.compass.framework.adapter.BaseBindViewHolder
import com.compass.framework.adapter.BaseMultiItemAdapter
import com.compass.framework.ext.gone
import com.compass.framework.ext.saveAs
import com.compass.framework.ext.visible
import com.compass.framework.glide.setUrl
import com.compass.framework.helper.CompassAppHelper
import com.compass.framework.utils.StatusBarSettingHelper.getScreenWidth
import com.compass.framework.utils.ViewUtils
import com.compass.framework.utils.dpToPx

/**
 * Description： 患者照片Adapter
 * Date:2023/12/11 14:15
 */


class PatientPictureAdapter constructor(private var itemType: Int) :
    BaseMultiItemAdapter<String>() {


    //用来实现多item布局
    override fun getDefItemViewType(position: Int): Int {
        return itemType
    }


    override fun onBindDefViewHolder(
        holder: BaseBindViewHolder<ViewBinding>,
        item: String?,
        position: Int
    ) {
        if (item == null) return
        //  //1、问诊单， 2、病历详情
        when (holder.itemViewType) {
            1 -> {
                val binding = holder.binding.saveAs<LayoutPatientPictureBinding>()
                binding.apply {
                    ViewUtils.setClipViewCornerRadius(imgPic, dpToPx(5))
                    ViewUtils.setClipViewCornerRadius(llMask, dpToPx(5))
                    imgPic.setUrl(item)
                    val width = getScreenWidth(CompassAppHelper.getApplication()) - dpToPx(70)
                    var layoutParams = relParent.layoutParams
                    layoutParams.width = width / 4
                    layoutParams.height = width / 4
                    if (position == 3) {
                        llMask.visible()
                    } else {
                        llMask.gone()
                    }

                }
            }

            else -> {
                val binding = holder.binding.saveAs<LayoutCaseHisPicItemBinding>()
                binding.apply {
                    ViewUtils.setClipViewCornerRadius(imgInfectedPart, dpToPx(5))
                    imgInfectedPart.setUrl(item)

                }

            }
        }
    }

    override fun getViewBinding(
        layoutInflater: LayoutInflater,
        parent: ViewGroup,
        viewType: Int
    ): ViewBinding {
        return when (viewType) {
            1 -> {
                LayoutPatientPictureBinding.inflate(layoutInflater, parent, false)
            }


            else -> {
                LayoutCaseHisPicItemBinding.inflate(layoutInflater, parent, false)
            }
        }

    }
}